package gitee.derumin.lib_for_derumin.helpers.config.configserializers;

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import net.minecraft.entity.EntityType;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;

public class EntityTypeSerializer implements ConfigFieldSerializer<EntityType<?>> {
    @Override
    public EntityType<?> jsonToObject(JsonElement element, String name) throws Exception {
        return Registries.ENTITY_TYPE.get(Identifier.tryParse(JsonHelper.asString(element, name)));
    }

    @Override
    public JsonElement objectToJson(Object contains) throws Exception {
        return new JsonPrimitive(Registries.ENTITY_TYPE.getId((EntityType<?>) contains).toString());
    }
}
